<link type="text/css" href="<?=base_url()?>css/themes/base/ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="<?=base_url()?>js/ui/ui.core.js"></script>
<script type="text/javascript" src="<?=base_url()?>js/ui/ui.datepicker.js"></script>
<script type="text/javascript">
$j(document).ready(function(){
	$j("#from-date").datepicker({ dateFormat: 'yy-mm-dd' });
	$j("#to-date").datepicker({ dateFormat: 'yy-mm-dd' });
});
function deleteorder(id) {
	if (confirm('Are you sure you want to delete this order?')) {
		window.location = '<?=base_url()?>admin/store/deleteorder/' + id;
	}
}
function export_csv(type) {
	if (confirm('This will export the order list to a csv file. Do you want to continue?')) {
		window.location = '<?=base_url()?>admin/store/exportorder/'+type;
	}
}
</script>
    	<div class="left">
        	<h1>Store Management</h1>
            <div class="bar">

            	<div class="text">Manage Orders</div>
            	<div class="cr"></div>
            </div>
            <div class="box">
            	<div class="box-1 rounded box-1-h" style="min-height:190px;">
                <form method="post" action="<?=base_url()?>admin/store/searchorder">
                	<h3>Search Orders
                    <!--
					<select class="box1-typecustomer" name="typecustomer">
						<option value="4" <?php if($this->session->userdata('by_typecustomer')==4) echo "selected=\"selected\""; ?>>Trade Customer</option>
						<option value="1" <?php if($this->session->userdata('by_typecustomer')==1) echo "selected=\"selected\""; ?>>Retail Customer</option>
					</select>--></h3>
                    <dl><dt>Customer Name</dt><dd><input type="text" class="textfield rounded" name="customer_name" value="<?=$this->session->userdata('customer_name')?>" /></dd></dl>
                    <dl><dt>Order ID</dt><dd><input type="text" class="textfield rounded" name="order_id" value="<?=$this->session->userdata('order_id')?>" /></dd></dl>
                    <dl><dt>From date</dt><dd><input type="text" class="textfield rounded" name="from_date" value="<?=$this->session->userdata('from_date')?>" id="from-date" /></dd></dl>
                    <dl><dt>To date</dt><dd><input type="text" class="textfield rounded" name="to_date" value="<?=$this->session->userdata('to_date')?>" id="to-date" /></dd></dl>
                    <dl><dt>By keyword</dt><dd><input type="text" class="textfield rounded" name="by_keyword" value="<?=$this->session->userdata('by_keyword')?>" id="by-keyword" /></dd></dl>
					<dl><dt></dt><dd><div style="width:208px"><div style="float:left"><div style="margin-top:3px; float:left"><input align="bottom" type="checkbox" class="movetop" name="by_status" <?php if($this->session->userdata('by_status')==1) echo "checked=\"checked\"" ?> value="1" /></div><div style="float:right"> &nbsp;Display Success</div></div><div style="float:right"><input type="submit" class="button rounded" value="Search" /></div></div></dd></dl>
                </form>
                <div style="clear:both"></div>
                </div>
                <div class="box-2 rounded box-1-h">
                	<h3>Sales Stats</h3>
                    <p class="desc">Click word for quick search</p>
                    <a href="<?=base_url()?>admin/store/order/search/total"><dl><dt>Sales total</dt><dd>$<?=$this->Order_model->sales_total()?></dd></dl></a>
                    <a href="<?=base_url()?>admin/store/order/search/month"><dl><dt><?=date('F')?> sales</dt><dd>$<?=$this->Order_model->sales_month(date('Y-m'))?></dd></dl></a>
                    <a href="<?=base_url()?>admin/store/order/search/week"><dl><dt>Week sales</dt><dd>$<?=$this->Order_model->sales_week()?></dd></dl></a>
                    <a href="<?=base_url()?>admin/store/order/search/day"><dl><dt>Today sales</dt><dd>$<?=$this->Order_model->sales_date(date('Y-m-d'))?></dd></dl></a>
                </div>
                <dl></dl>
            </div>
            <hr />
            <div class="box bgw">
				<?php 
					$seg = $this->uri->segment(5);
				?>
            	<h3>Orders List &nbsp;&nbsp;<input type="button" class="button rounded" value="Export to CSV" onclick="export_csv('<?=$seg?>')" /></h3>
                <p class="desc">Below you can find your last 20 orders. Use the search function to search through all orders in the system. <?php if(isset($total)) { ?><span class="totalsale">Total sales: <b>$<?=$total?></b></span><?php } ?></p><br />
                <div class="row-title">
                	<div class="order-id">Order ID</div>
                    <div class="order-customer">Franchisee/Trade Name</div>
                    <div class="order-date">Order Date</div>
                    <div class="order-total">Total</div>
                    <div class="order-status">Status</div>
                    <div class="order-func2">Functions</div>
                </div>
                <div id="subcat">
                	<?php foreach($orders as $order) { ?>
                    <div class="row-item">
                    	<div class="order-id"><?=$order['id']?></div>
                        <div class="order-customer"><?php if($order['franchisee'] != ''){ echo to_short($order['franchisee'],20);} else{ echo $order['tradingname'];}?>
						</div>
                        <div class="order-date"><?=date('d-m-Y',strtotime($order['order_time']))?></div>
                        <div class="order-total"><?=$order['total']?></div>
                        <div class="order-status<?php if($order['status'] == 'successful') print ' green'; else print ' error'; ?>"><?=ucwords($order['status'])?></div>
                        <div class="order-func"><a href="<?=base_url()?>admin/store/order/view/<?=$order['id']?>"><img src="<?=base_url()?>img/backend/icon-view.png" /></a></div>
                        <div class="order-func"><a href="javascript:deleteorder(<?=$order['id']?>)"><img src="<?=base_url()?>img/backend/icon-delete.png" /></a></div>
                    </div>
                    <?php } ?>
                </div>
            </div>
        </div>
        
